﻿using Avalon.Business.ViewModels;
using Avalon.Repository;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Avalon.Business.Pipelines.Character
{
    public class CharacterPipelines
    {
        public IEnumerable<VMCharacter> GetCharacters()
        {
            var repo = new Repository<Data.Models.Character>();
            foreach (var character in repo.Get())
            {
                yield return new VMCharacter() { Name = character.Name };
            }
        }

        public void AddCharacter(VMCharacter character)
        {
            var repoCharacter = new Repository<Data.Models.Character>();
            var repoSetting = new Repository<Data.Models.Setting>();

            var temp = new Data.Models.Character()
            {
                Id = Guid.NewGuid(),
                Name = character.Name,
                Statistics = repoSetting.Get().FirstOrDefault().Statistics.Select(stat => new Data.Models.CharacterStatistic() { Name = stat.Name }).ToList()
            };

            repoCharacter.Add(temp);
            repoCharacter.SaveChanges();
        }
    }
}
